package com.hutra.utils {
	import flash.net.SharedObject;
	
	/**
	 *  Usage Example
	 *  import SharedObjectManager;
	 *  SharedObjectManager.stage.setShared('hungconcon');
	 *  SharedObjectManager.stage.setCookie("test",3);
	 *  SharedObjectManager.stage.getCookie("test"); // 3
	 * @author hungconcon
	 */
	public class SharedObjectManager {
		
		public static var module:SharedObjectManager;
		public var cookie:SharedObject;
		
		public function SharedObjectManager() {
		}
		
		public function setShared(key:String):void {
			cookie = SharedObject.getLocal(key);
		}
		
		public function getCookie(key:String):Object {
			return cookie.data[key] as Object;
		}
		
		public function setCookie(key:String, value:*):void {
			cookie.data[key] = value;
			save();
		}
		
		public function save():void {
			cookie.flush();
		}
		
		public static function stage():SharedObjectManager {
			if (!module)
				module = new SharedObjectManager();
			return module;
		}
	}
}
